﻿#region Using Statements
using System;
using Babushka.GameModels;
using Babushka.GameModels.Tiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
#endregion

namespace Babushka
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Game
    {
        internal static GraphicsDeviceManager Graphics;
        internal static SpriteBatch SpriteBatch;

        LevelPlayer player;
        public Game1() : base()
        {
            Graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
            this.IsMouseVisible = true;
            //Graphics.PreferredBackBufferWidth = 320;
            //Graphics.PreferredBackBufferHeight = 320;
            //Graphics.IsFullScreen = true;
            Graphics.ApplyChanges();

            player = new LevelPlayer();
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            
            SpriteBatch = new SpriteBatch(GraphicsDevice);

            Resources.Graphics.InitGraphics(Content);
            Tile.InitTiles();
            Level lvl = new Level(10, 10);
            for (int i = 0; i < 10; i++)
            {
                lvl[i, 9] = Tile.Tiles[0];
            }
            player.Play(lvl);
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            player.Update();
            Console.Clear();
            Console.WriteLine(gameTime.ElapsedGameTime);
            Console.WriteLine(player);
            base.Update(gameTime);
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            player.Draw();            

            base.Draw(gameTime);
        }
    }
}
